﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using Website.Logger;
using DAL;
using BOL;
using System.Web.Script.Services;
using System.Web.Services;
using WebLib;

namespace UILGestion.Admin.Almacenes
{
    public partial class AlmacenReadForm : System.Web.UI.Page
    {
       
        private void FormatForm()
        {
             ShowAllComboBoxNew();
             LoadRecepcionDoc(int.Parse(internalid.Value));
            
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {

                    internalid.Value = (string)Request.QueryString["id"];
                                       menuCtrl1.loadMenuSeguridad();
                    FormatForm();

               

                }


            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }

        }

        
        private void ShowAllComboBoxNew()
        {
            
            
        }



      


        protected void btnContinue_OnClick(object sender, EventArgs e)
        {
         
            try
            {
            if ((sender as Button).Text == refreshButton.Text)
            {
                FormatForm();
            }
                if ((sender as Button).Text == EditarButton.Text)
            {
                Response.Redirect(String.Format("AlmacenInsertForm.aspx?id={0}&type=E",internalid.Value),true);
            }
                if ((sender as Button).Text == nuevoButton.Text)
            {
                Response.Redirect(String.Format("AlmacenInsertForm.aspx?id={0}&type=A",internalid.Value),true);
            }
                if ((sender as Button).Text == EliminarButton.Text)
                {
                    AlmacenBL bol = new AlmacenBL();
                    bol.Delete(int.Parse(internalid.Value));
                    Response.Redirect(String.Format("AlmacenListForm.aspx", idObra.Value), false);
                }
                
           }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);
               

            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);
               
            }
        }

  
     
        protected void refreshButton_Click(object sender, EventArgs e)
        {
        }

       
      


        private void LoadRecepcionDoc(int idAlmacen)
        {

            var almacen = DbUtil.Db.Almacens.Single(p=>p.idInternal==idAlmacen);

            idInternalLabel.Text = almacen.idInternal.ToString();
            descripcionLabel.Text = almacen.descripcion;
            direccionLabel.Text = almacen.direccion;

            responsableLabel.Text = almacen.Empleado.descripcion;
            
            
            fechaLabel.Text = almacen.fechaCre.Value.ToShortDateString();
            usuarioLabel.Text = almacen.Empleado1.descripcion;
            usuarioModLBL.Text = almacen.Empleado2.descripcion;
            fechaModLBL.Text = almacen.fechaMod.Value.ToShortDateString();

            empresaLBL.Text = almacen.Empresa.descripcion;
            proyectoLBL.Text = almacen.Obra.Proyecto.descripcion;
            obraLBL.Text = almacen.Obra.Proyecto.descripcion;

            
          

        }
       

     
     




       


    }

}
